<!DOCTYPE html>
<html lang="en">
<title>编辑教练</title>
<#import "/layout/layout.html" as body/>
<@body.page>
<style>
    textarea:required:invalid, input:required:invalid {
        background-color: lightyellow;
    }
</style>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5 class="pull-left">编辑教练</h5>
                </div>
                <form class="form-horizontal" name="editForm" id="editForm"
                      enctype="multipart/form-data" onsubmit="return false;">
                    <div class="ibox-content">
                        <input type="hidden" name="id" value="${coach.id}">
                        <div class="form-group"><label class="col-sm-2">基础信息</label></div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">登陆手机号</label>
                            <div class="col-sm-10">
                                <input class="form-control" id="mobile" name="mobile" value="${(coach.mobile)!}"/>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">教练姓名</label>
                            <div class="col-sm-10">
                                <input class="form-control" id="nickName" name="nickName" value="${(coach.nickName)!}" required maxLength="50"/>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">个性签名</label>
                            <div class="col-sm-10"><input class="form-control" id="personalStatus" name="personalStatus" value="${(coach.personalStatus)!}" required maxLength="100"/></div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">教练类型</label>
                            <div class="col-sm-10">
                                <select class="form-control m-b" name="workType" id="workType">
                                    <option value="">请选择</option>
                                    <option value="1" <#if coach ?? && coach.workType?? && coach.workType = 1>selected</#if> >全职</option>
                                    <option value="2" <#if coach ?? && coach.workType?? && coach.workType = 2>selected</#if> >兼职</option>
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">所属门店</label>
                            <div class="col-sm-10">
                                <select class="form-control m-b" id="storeId" name="storeId">
                                    <#if stores??>
                                        <#list stores as store>
                                            <option value="${store.id}" <#if store.id == coach.storeId> selected</#if> >${store.storeName}</option>
                                        </#list>
                                    </#if>
                                </select>
                            </div>
                        </div>

                        <!--timo add-->
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">是否主教练</label>
                            <div class="col-sm-10" id="chief_coac_div">
                                <div class="checkbox-inline i-checks"><label for="isChiefCoachYes"> <input type="radio" id="isChiefCoachYes" value="1" name="isChiefCoach"  <#if coach.isChiefCoach != 2 >checked</#if> <i></i> 是 </label></div>
                                <div class="checkbox-inline i-checks"><label for="isChiefCoachNo"> <input type="radio" id="isChiefCoachNo" value="2" name="isChiefCoach"  <#if coach.isChiefCoach == 2 >checked</#if>> <i></i> 不是 </label></div>
                            </div>
                        </div>

                        <div id="is_chief_coach_show">
                            <div class="form-group"><label class="col-sm-2 control-label">主教练</label>
                                <div class="col-sm-10">
                                    <select class="form-control m-b" id="parentCoachId" name="parentCoachId">
                                        <#if chiefCoachList??>
                                        <#list chiefCoachList as list>
                                            <option value="${list.id}">${list.nickName}</option>
                                        </#list>
                                    </#if>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <!--timo add-->
                        <div class="hr-line-dashed"></div>
                        <div class="form-group" id="data_1">
                            <label class="col-sm-2 control-label">出生日期</label>
                            <div class="col-sm-10">
                                <div class="input-group date">
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    <input type="text" class="form-control" id="birthdate" name="birthdate" value="${coach.birthdate?string('yyyy-MM-dd')}"/>
                                </div>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">性别</label>
                            <div class="col-sm-10">
                                <select class="form-control m-b" name="gender">
                                    <option value="1" <#if coach?? && coach.gender='1'> selected</#if> >男</option>
                                    <option value="2" <#if coach?? && coach.gender='2'> selected</#if> >女</option>
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">身高</label>
                            <div class="col-sm-10">
                                <input type="number" class="form-control" id="stature" name="stature" maxLength="3" value="${coach.stature!}"/>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">体重</label>
                            <div class="col-sm-10">
                                <input type="number" class="form-control" id="weight" name="weight" maxLength="3" value="${coach.weight!}"/>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">身材</label>
                            <div class="col-sm-10">
                                <select class="form-control m-b" id="bodyStature" name="bodyStature">
                                    <#if stature_man??>
                                        <#list stature_man?keys as key>
                                            <option value="${key}">${stature_man[key]}</option>
                                        </#list>
                                    </#if>
                                </select>
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group margin-top"><label class="col-sm-2">教学信息</label></div>

                        <div class="hr-line-dashed "></div>
                        <div class="form-group"><label class="col-sm-2 control-label">教练上课类型</label>
                            <div class="col-sm-10">
                                <div class="checkbox-inline i-checks"><label for="team"> <input type="checkbox" id="team" value="1" name="isTeam"  <#if coach?? && coach.isTeam?? && coach.isTeam == 1>checked</#if> > 团课 </label></div>
                                <div class="checkbox-inline i-checks"><label for="private"> <input type="checkbox" id="private" value="1" name="isPrivate" <#if coach?? && coach.isPrivate?? && coach.isPrivate == 1>checked</#if> > 私教 </label></div>
                                <div class="checkbox-inline i-checks"><label for="camp"> <input type="checkbox" id="camp" value="1" name="isCamp" <#if coach?? && coach.isTeam?? && coach.isCamp == 1>checked</#if> >  训练营 </label></div>
                            </div>
                        </div>

                        <div id="private_show">
                            <div class="hr-line-dashed"></div>
                            <div class="form-group"><label class="col-sm-2 control-label">是否上私教体测</label>
                                <div class="col-sm-10">
                                    <div class="checkbox-inline i-checks"><label for="isPrivateBodyExaminationYes"> <input type="radio" id="isPrivateBodyExaminationYes" value="1" name="isPrivateBodyExamination" <#if coach?? && coach.isPrivateBodyExamination?? && coach.isPrivateBodyExamination == 1>checked</#if> > <i></i> 上 </label></div>
                                    <div class="checkbox-inline i-checks"><label for="isPrivateBodyExaminationNo"> <input type="radio" id="isPrivateBodyExaminationNo" value="2" name="isPrivateBodyExamination"  <#if coach?? && coach.isPrivateBodyExamination?? && coach.isPrivateBodyExamination == 2>checked</#if>  > <i></i> 不上 </label></div>
                                </div>
                            </div>

                            <div class="hr-line-dashed"></div>
                            <div class="form-group"><label class="col-sm-2 control-label">是否上私教体验</label>
                                <div class="col-sm-10">
                                    <div class="checkbox-inline i-checks"><label for="isPrivateExperienceYes"> <input type="radio" id="isPrivateExperienceYes" value="1" name="isPrivateExperience" <#if coach?? && coach.isPrivateExperience?? && coach.isPrivateExperience == 1>checked</#if> > <i></i> 上 </label></div>
                                    <div class="checkbox-inline i-checks"><label for="isPrivateExperienceNo"> <input type="radio" id="isPrivateExperienceNo" value="2" name="isPrivateExperience"  <#if coach?? && coach.isPrivateExperience?? && coach.isPrivateExperience == 2>checked</#if> > <i></i> 不上 </label></div>
                                </div>
                            </div>

                            <!--<div class="hr-line-dashed"></div>-->
                            <!--<div class="form-group"><label class="col-sm-2 control-label">是否上私教请咨询</label>-->
                                <!--<div class="col-sm-10">-->
                                    <!--<div class="checkbox-inline i-checks"><label for="isPrivateConsultYes"> <input type="radio" id="isPrivateConsultYes" value="1" name="isPrivateConsult" <#if coach?? && coach.isPrivateConsult?? && coach.isPrivateConsult == 1>checked</#if> > <i></i> 上 </label></div>-->
                                    <!--<div class="checkbox-inline i-checks"><label for="isPrivateConsultNo"> <input type="radio" id="isPrivateConsultNo" value="2" name="isPrivateConsult" <#if coach?? && coach.isPrivateConsult?? && coach.isPrivateConsult == 2>checked</#if> > <i></i> 不上 </label></div>-->
                                <!--</div>-->
                            <!--</div>-->
                            <!--<div class="hr-line-dashed"></div>-->
                            <!--<div class="form-group"><label class="col-sm-2 control-label">是否私教体测/体验轮排</label>-->
                                <!--<div class="col-sm-10">-->
                                    <!--<div class="checkbox-inline i-checks"><label for="isPrivateCoachSortYes"> <input type="radio" id="isPrivateCoachSortYes" value="1" name="isPrivateCoachSort"  <#if coach?? && coach.isPrivateCoachSort?? && coach.isPrivateCoachSort == 1>checked</#if> > <i></i> 轮排 </label></div>-->
                                    <!--<div class="checkbox-inline i-checks"><label for="isPrivateCoachSortNo"> <input type="radio" id="isPrivateCoachSortNo" value="2" name="isPrivateCoachSort" <#if coach?? && coach.isPrivateCoachSort?? && coach.isPrivateCoachSort == 2>checked</#if> > <i></i> 不轮排 </label></div>-->
                                <!--</div>-->
                            <!--</div>-->
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">从业时长</label>
                            <div class="col-sm-10">
                                <select class="form-control m-b" name="workTimes">
                                    <#if workTimes??>
                                        <#list workTimes?keys as key>
                                            <option value="${key}"
                                            <#if key == coach.workTimes?string> selected</#if>
                                            >${workTimes[key]}</option>
                                        </#list>
                                    </#if>
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">授课风格</label>
                            <div class="col-sm-10">
                                <select class="form-control m-b" name="teachStyle">
                                    <#if teachStyles??>
                                        <#list teachStyles?keys as key>
                                            <option value="${key}"
                                            <#if key == coach.teachStyle?string> selected</#if>
                                            >${teachStyles[key]}</option>
                                        </#list>
                                    </#if>
                                </select>
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">擅长课程</label>
                            <input id="goodCourse" name="goodCourse" value="${coach.goodCourse!}" type="hidden">
                            <div class="col-sm-10">
                                <div id="magicsuggest"></div>
                            </div>
                        </div>
                        
                        <div class="hr-line-dashed"></div>
                        <div class="form-group" id="teachCourse_div"><label class="col-sm-2 control-label">所授课程</label>
                            <input id="teachCourse" name="teachCourse" type="hidden" value="${coach.teachCourse!}">
                            <div class="col-sm-10">
                                <div id="magicsuggest_teachCourse"></div>
                            </div>
                        </div>
	
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">累计私教学员</label>
                            <div class="col-sm-10">
                                <select class="form-control m-b" id="totalStudent" name="totalStudent">
                                    <#if totalStudents??>
                                        <#list totalStudents?keys as key>
                                            <option value="${key}"
                                            <#if key == coach.totalStudent?string>selected</#if>
                                            >${totalStudents[key]}</option>
                                        </#list>
                                    </#if>
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">认证信息</label>
                            <div class="col-sm-10">
                                <#if coach??>
                                    <#if coach.authInfo??>
                                        <#list coach.authInfo?split("||") as authinfo>
                                            <#if authinfo != "">
                                                <textarea class="form-control" rows="1" id="authInfo" name="authInfo" maxLength="30" style="height:35px;margin-bottom: 20px;">${authinfo}</textarea>
                                            <#else>
                                                <textarea class="form-control" rows="1" id="authInfo" name="authInfo" maxLength="30" style="height:35px;margin-bottom: 20px;"></textarea>
                                            </#if>
                                        </#list>
                                    </#if>
                                    <!--<#if coach.authInfo =="">-->
                                    <!--</#if>-->
                                </#if>
                                <span id="authInfo-l" class="help-block text-right">0/30</span>
                                <div id="info-more" class="overflow"></div>
                                <span class="help-block text-right"><a href="javascript:void(0);" onclick="addText(this);">添加认证信息</a></span>
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">私教案例</label>
                            <div class="col-sm-10">
                                <input id="resourceSampleTitle" name="resourceSampleTitle" value="${coach.resourceSampleTitle!}" style="margin-bottom: 15px;" class="form-control" placeholder="请填写私教案例文章的标题"/>
                                <input id="resourceSampleUrl" name="resourceSampleUrl" value="${coach.resourceSampleUrl!}" class="form-control" placeholder="请填写私教案例的文章链接" />
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2">信息展示</label></div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">教练微信二维码</label>
                            <input id="weixinQrCode" name="weixinQrCode" type="hidden" value="${(coach.weixinQrCode)!}">
                            <div class="col-sm-10">
                                <div id="weixinQrCode_pic" style="min-height: 230px;" class="dropzone">
                                    <div class="dropzone-previews"></div>
                                </div>
                            </div>
                        </div>


                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">教练头像</label>
                            <input id="headImg" name="headImg" type="hidden" value="${(coach.headImg)!}">
                            <div class="col-sm-10">
                                <div id="headImg_pic" name="dropzone_headImg" style="min-height: 230px;" class="dropzone">
                                    <div class="dropzone-previews"></div>
                                </div>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">自我介绍</label>
                            <div class="col-sm-10">
                                <textarea class="form-control" rows="3" id="briefing" name="briefing" maxLength="600">${coach.briefing!}</textarea>
                                <span class="help-block m-b-none">教练的健身格言，或经历描述、最想让学员知道的信息 <i id="briefing-l" class="pull-right">0/600</i></span>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">视频链接</label>
                            <div class="col-sm-10"><input type="text" class="form-control" id="link" name="link" value="${coach.link!}" maxLength="255"></div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">视频封面图</label>
                            <input id="url" name="url" type="hidden" value="${coach.url!}">
                            <div class="col-sm-10">
                                <div id="video_preview" tyle="min-height: 230px;" class="dropzone">
                                    <div class="dropzone-previews"></div>
                                </div>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">类别硬照</label>
                            <input id="categoryPic" name="categoryPic" type="hidden" value="${coach.categoryPic!}">
                            <div class="col-sm-10">
                                <div id="category_pic" style="min-height: 230px;" class="dropzone">
                                    <div class="dropzone-previews"></div>
                                </div>
                                <div class="m text-left">
                                    <small>大小不能超过1.5M</small>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="ibox-content overflow">
                        <div class="col-sm-12">
                            <button type="button" class="btn btn-default pull-left" onClick="goBackList()">取消修改</button>
                            <button id="saveBtn" type="button" class="btn btn-success pull-right" onClick="formSubmit()">确定</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<!--upload-->
<script type="text/javascript" src="${baseUrl}js/upload/promise.min.js"></script>
<script type="text/javascript" src="${baseUrl}js/upload/aliyun-oss-sdk.min.js"></script>
<script type="text/javascript" src="${baseUrl}js/upload/webToOss.js"></script>
<link href="${baseUrl}css/plugins/magicsuggest/magicsuggest-min.css" rel="stylesheet">
<script src="${baseUrl}js/plugins/dropzone/dropzone.js"></script>

<script>
    var goodCourseArr = new Array();
    var courseStandardList = ${courseStandards!};
    var headPicList = new Array();
    var videoLinkPicList = new Array();
    var categoryPicList = new Array();
    var myDropzone;
    var myDropzone1;
    var myDropzone2;
    var myDropzone3;
    var stature_man_json = ${stature_man_json!};
    var stature_woman_json = ${stature_woman_json!};
    var body_stature = '${coach.bodyStature!}';

    //添加认证信息
    function addText() {
        $("#info-more").append('<div class="remove-this"><div class="col-sm-10 padding-left-0">' +
                '<textarea class="form-control" rows="1" name="authInfo" maxLength="30" style="height:35px;margin-bottom: 20px;"></textarea></div>' +
                '<a href="javascript:void(0);" class="btn btn-sm btn-default col-sm-2" onclick="removeText(this);">删除</a></div>');
    }
    //移除认证信息
    function removeText(obj) {
        $(obj).parent(".remove-this").remove();
    }
    //返回列表
    function goBackList() {
        window.location = "to_coach_list";
    }
    //保存
    function formSubmit() {
        $('#goodCourse').val(goodCourseArr.toString());
//        debugger
        var isCheck = true;
        if ($("#mobile").val().trim().length <= 0) {
            swal("错误!", "请先填写登陆手机号!", "error");
            isCheck = false;
            return false;
        }
        var pattern = /^1[3456789][0-9]{9}$/;
        if (!$("#mobile").val().trim().match(pattern)) {
            swal("错误!", "请先正确填写登陆手机号!", "error");
            isCheck = false;
            return false;
        }
        if ($("#nickName").val().trim().length <= 0) {
            swal("错误!", "请先填写教练姓名!", "error");
            isCheck = false;
            return false;
        }
        if ($("#workType").val().length <=0) {
            swal("错误!", "请先选择教练类型!", "error");
            isCheck = false;
        }
        if ($("#storeId").val().trim().length <= 0) {
            swal("错误!", "请先选择所属门店!", "error");
            isCheck = false;
            return false;
        }
        if ($("#birthdate").val().trim().length <= 0) {
            swal("错误!", "请先选择出生日期!", "error");
            isCheck = false;
            return false;
        }
        if ($("#stature").val().length <= 0) {
            swal("错误!", "请先填写身高!", "error");
            isCheck = false;
            return false;
        }
        if ($("#weight").val().length <= 0) {
            swal("错误!", "请先填写体重!", "error");
            isCheck = false;
            return false;
        }

        //验证门店
//            if($("#storeId").val() == 0){
//                document.getElementById("storeId").setCustomValidity("请选择门店");
//                swal("错误!", "请先选择门店!", "error");
//                isCheck = false;
//                return false;
//            }else{
//                document.getElementById("storeId").setCustomValidity("");
//            }
        if ($("#totalStudent").val().trim().length <= 0) {
            swal("错误!", "请先选择累计私教学员", "error");
            isCheck = false;
            return false;
        }
        //验证信息
//            if($("#authInfo").val().trim().length <=0){
//                swal("错误!", "请先填写认证信息", "error");
//                isCheck = false;
//                return false;
//            }
        //验证教练二维码
        if($("#weixinQrCode").val().length <=0){
            swal("错误!", "请先上传教练二维码!", "error");
            isCheck = false;
            return false;
        }

        //验证头像
        $("#headImg").val(headPicList.join(","));
        if ($("#headImg").val().trim().length <= 0) {
            swal("错误!", "请先上传教练头像!", "error");
            isCheck = false;
            return false;
        } else {
            if (headPicList.length != 1) {
                swal("错误!", "请先确定上传1张数量的教练头像!", "error");
                isCheck = false;
                return false;
            }
        }
        //自我介绍
        if ($("#briefing").val().trim().length <= 0) {
            swal("错误!", "请先输入自我介绍!", "error");
            isCheck = false;
            return false;
        }

        //视频链接
//            if($("#link").val().length<=0) {
//                swal("错误!", "请先输入视频链接!", "error");
//                isCheck = false;
//                return false;
//            }

//            if($("#url").val().length<=0) {
//                swal("错误!", "请先上传视频封面图!", "error");
//                isCheck = false;
//                return false;
//            } else {
//                if (videoLinkPicList.length != 1) {
//                    swal("错误!", "请先确定上传1张数量的视频封面图!", "error");
//                    isCheck = false;
//                    return false;
//                }
//            }

        $("#url").val(videoLinkPicList.join(","));
        if (videoLinkPicList.length > 0 && videoLinkPicList.length != 1) {
            swal("错误!", "请先确定上传1张数量的视频封面图!", "error");
            isCheck = false;
            return false;
        }
        $("#categoryPic").val(categoryPicList.join(","));
        if ($("#categoryPic").val().length <= 0) {
            swal("错误!", "请先上传类别硬照!", "error");
            isCheck = false;
            return false;
        }
//        else {
//            if (categoryPicList.length % 2 != 0) {
//                swal("错误!", "请先上传偶数量的类别硬照!", "error");
//                isCheck = false;
//                return false;
//            }
//        }

        if (!isCheck) {
            return false;
        }
        var param = $("#editForm").serialize();
//        debugger
        $("#saveBtn").attr('disabled', "true");
        $.ajax({
            type: "post",
            url: "coach_save",
            data: param,
            success: function (data) {
                if (data == "success") {
                    swal("保存成功!", "页面即将重新加载,请稍后...", "success");
                    window.setTimeout(function () {
                        window.location = "to_coach_list";
                    }, 1000);
                } else {
                    swal("保存失败!", "", "error");
                }
            }
        });
    }


    $(document).ready(function () {
        var isChiefCoach = ${coach.isChiefCoach!};
        // $("#coachId").val(courseJson.coachId);
        var parentCoachId = ${coach.parentCoachId!0};
        // 选择主教练隐藏
        if (isChiefCoach == 1) {
            $('#is_chief_coach_show').hide();
        } else if (isChiefCoach ==2) {
            $('#is_chief_coach_show').show();
        }
        if(parentCoachId > 0){
            $("#parentCoachId").val(parentCoachId);
        }
        // 选择主教练隐藏
        $('#chief_coac_div input').on('ifChecked', function () {
            var this_val = $(this).val();
            if (this_val === '1') {
                $('#is_chief_coach_show').hide(400);
            } else if (this_val === '2') {
                $('#is_chief_coach_show').show(400);
            }
        });

        $('#private').on('ifChecked', function () {
            $('#private_show').show();
            // $('#isPrivateBodyExaminationYes, #isPrivateExperienceYes, #isPrivateConsultYes, #isPrivateCoachSortYes').iCheck('check');
            $('#isPrivateBodyExaminationYes, #isPrivateExperienceYes').iCheck('check');
        });

        $('#private').on('ifUnchecked', function () {
           $('#private_show').hide();
           // $('#isPrivateBodyExaminationNo, #isPrivateExperienceNo, #isPrivateConsultNo, #isPrivateCoachSortNo').iCheck('check');
            $('#isPrivateBodyExaminationNo, #isPrivateExperienceNo').iCheck('check');
        });


        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green'
        });

        //下拉插件
        var ms;
        if ($('#goodCourse').val().trim().length <= 0) {
            ms = $('#magicsuggest').magicSuggest({
                data: courseStandardList,
                placeholder: '请输入搜索或选择',
                required: false,
                expandOnFocus: true,
                strictSuggest: true,
                displayField: 'name',
                valueField: 'name'
            });
        } else {
            ms = $('#magicsuggest').magicSuggest({
                data: courseStandardList,
                placeholder: '请输入搜索或选择',
                required: false,
                expandOnFocus: true,
                strictSuggest: true,
                displayField: 'name',
                valueField: 'name',
                value: $('#goodCourse').val().split('#')
            });
            goodCourseArr = ms.getValue();
        }
        $(ms).on('selectionchange', function () {
            console.log('DATA---->>' + JSON.stringify(this.getValue()));
            goodCourseArr = this.getValue();
        });
        
        var teachCourseList = $("#teachCourse").val();
        var magicsuggest_teachCourse = $('#magicsuggest_teachCourse').magicSuggest({
            data: courseStandardList,
            placeholder: '请输入搜索或选择',
            editable: false,
            required: false,
            expandOnFocus: true,
            strictSuggest: true,
            displayField: 'name',
            valueField: 'name'
			
        });
        debugger;
        $(magicsuggest_teachCourse).on('selectionchange', function () {
            $("#teachCourse").val(this.getValue());
        });
        if(teachCourseList.indexOf("#") > 0){
        	magicsuggest_teachCourse.setValue(teachCourseList.split("#"));
        }else if(teachCourseList.length > 0){
        	magicsuggest_teachCourse.setValue([teachCourseList]);
        }

        $('#birthdate').datepicker({
            todayBtn: "linked",
            keyboardNavigation: false,
            forceParse: false,
            calendarWeeks: true,
            autoclose: true,
            format: "yyyy-mm-dd"
        });


        //教练微信二维码
        Dropzone.autoDiscover = false;
        myDropzone = new Dropzone("#weixinQrCode_pic", {
            url: "upload_pic",
            uploadMultiple: false,
            addRemoveLinks: true,
            dictDefaultMessage: "将文件拖到此处上传",
            dictFileTooBig: "文件过大",
            dictCancelUpload: "取消上传",
            dictRemoveFile: "移除文件",
            maxFilesize: 10.5,
            acceptedFiles: ".jpg,.jpeg,.png",
            method: 'post',
            filesizeBase: 1024,

            init: function () {
                    var url = $("#weixinQrCode").val();
                    if (!url || url.length <= 0) {
                        url = "";
                    }
                    this.emit("initimage", url);
                this.on("error", function (file, response, XMLHttpRequest) {
                    swal("图片上传异常!", "图片服务器出错,即将清除无效图片,请稍后重新上传...", "error");
                    window.setTimeout(function () {
                        $('#weixinQrCode_pic .dz-image-preview.dz-error').remove()
                    }, 1000);
                });
                this.on("success", function (file, response, e) {
                    if (response.error) {
                        $(file.previewTemplate).children('.dz-error-mark').css('opacity', '1')
                    } else {
                        $("#weixinQrCode").val(response.url);
                    }
                });
                this.on("sending", function (file, xhr, formData) {
                    formData.append("filesize", file.size);
                });
                this.on("removedfile", function (file) {
                    $("#weixinQrCode").val();
                });
            }
        });

        //头像
        myDropzone1 = new Dropzone("#headImg_pic", {
            url: "upload_pic",
            uploadMultiple: false,
            addRemoveLinks: true,
            dictDefaultMessage: "将文件拖到此处上传",
            dictFileTooBig: "文件过大",
            dictCancelUpload: "取消上传",
            dictRemoveFile: "移除文件",
            maxFilesize: 10.5,
            acceptedFiles: ".jpg,.jpeg,.png",
            method: 'post',
            filesizeBase: 1024,

            init: function () {
                var url = $("#headImg").val();
                if (!url || url.length <= 0) {
                    url = "";
                } else {
                    var larr = url.split(",");
                    if (larr.length > 0) {
                        for (var i = 0; i < larr.length; i++) {
                            headPicList.push(larr[i]);
                        }
                    }
                }
                this.emit("initimage", url);
                this.on("error", function (file, response, XMLHttpRequest) {
                    swal("图片上传异常!", "图片服务器出错,即将清除无效图片,请稍后重新上传...", "error");
                    window.setTimeout(function () {
                        $('#headImg_pic .dz-image-preview.dz-error').remove()
                    }, 1000);
                });
                this.on("success", function (file, response, e) {
                    if (response.error) {
                        $(file.previewTemplate).children('.dz-error-mark').css('opacity', '1')
                    } else {
                        headPicList.push(response.url);
                    }
                });
                this.on("sending", function (file, xhr, formData) {
                    formData.append("filesize", file.size);
                });
                this.on("removedfile", function (file) {
                    var responseJson = null;
                    if (file && file.xhr && file.xhr.responseText) {
                        responseJson = $.parseJSON(file.xhr.responseText);
                    }
                    if (responseJson) {
                        $.each(headPicList, function (i, data) {
                            if (headPicList[i].indexOf(responseJson.url) > -1) {
                                headPicList.splice(i, 1);
                            }
                        });
                    }
                    if (file.name.length > 0) {
                        for (var i = 0; i < headPicList.length; i++) {
                            if (headPicList[i].indexOf(file.name) > -1) {
                                headPicList.splice(i, 1);
                                break
                            }
                        }
                        console.log("文件 " + file.name + " 被移除");
                    }
                });
            }
        });

        //视频封面图
        myDropzone2 = new Dropzone("#video_preview", {
            url: "upload_pic",
            uploadMultiple: false,
            addRemoveLinks: true,
            dictDefaultMessage: "将文件拖到此处上传",
            dictFileTooBig: "文件过大",
            dictCancelUpload: "取消上传",
            dictRemoveFile: "移除文件",
            maxFilesize: 10.5,
            acceptedFiles: ".jpg,.jpeg,.png",
            method: 'post',
            filesizeBase: 1024,

            init: function () {
                var url = $("#url").val();
                if (!url || url.length <= 0) {
                    url = "";
                } else {
                    var larr = url.split(",");
                    if (larr.length > 0) {
                        for (var i = 0; i < larr.length; i++) {
                            videoLinkPicList.push(larr[i]);
                        }
                    }
                }
                this.emit("initimage", url);
                this.on("error", function (file, response, XMLHttpRequest) {
                    swal("图片上传异常!", "图片服务器出错,即将清除无效图片,请稍后重新上传...", "error");
                    window.setTimeout(function () {
                        $('#video_preview .dz-image-preview.dz-error').remove()
                    }, 1000);
                });
                this.on("success", function (file, response, e) {
                    if (response.error) {
                        $(file.previewTemplate).children('.dz-error-mark').css('opacity', '1')
                    } else {
                        videoLinkPicList.push(response.url);
                    }
                });
                this.on("sending", function (file, xhr, formData) {
                    formData.append("filesize", file.size);
                });
                this.on("removedfile", function (file) {
                    var responseJson = null;
                    if (file && file.xhr && file.xhr.responseText) {
                        responseJson = $.parseJSON(file.xhr.responseText);
                    }
                    if (responseJson) {
                        $.each(videoLinkPicList, function (i, data) {
                            if (videoLinkPicList[i].indexOf(responseJson.url) > -1) {
                                videoLinkPicList.splice(i, 1);
                            }
                        });
                    }
                    if (file.name.length > 0) {
                        for (var i = 0; i < videoLinkPicList.length; i++) {
                            if (videoLinkPicList[i].indexOf(file.name) > -1) {
                                videoLinkPicList.splice(i, 1);
                                break
                            }
                        }
                        console.log("文件 " + file.name + " 被移除");
                    }
                });
            }
        });

        //类别硬照
        myDropzone3 = new Dropzone("#category_pic", {
            url: "upload_pic",
            uploadMultiple: false,
            addRemoveLinks: true,
            dictDefaultMessage: "将文件拖到此处上传",
            dictFileTooBig: "文件过大",
            dictCancelUpload: "取消上传",
            dictRemoveFile: "移除文件",
            maxFilesize: 10.5,
            acceptedFiles: ".jpg,.jpeg,.png",
            method: 'post',
            filesizeBase: 1024,

            init: function () {
                var url = $("#categoryPic").val();
                if (!url || url.length <= 0) {
                    url = "";
                } else {
                    var larr = url.split(",");
                    if (larr.length > 0) {
                        for (var i = 0; i < larr.length; i++) {
                            categoryPicList.push(larr[i]);
                        }
                    }
                }
                this.emit("initimage", url);
                this.on("error", function (file, response, XMLHttpRequest) {
                    swal("图片上传异常!", "图片服务器出错,即将清除无效图片,请稍后重新上传...", "error");
                    window.setTimeout(function () {
                        $('#category_pic .dz-image-preview.dz-error').remove()
                    }, 1000);
                });
                this.on("success", function (file, response, e) {
                    if (response.error) {
                        $(file.previewTemplate).children('.dz-error-mark').css('opacity', '1')
                    } else {
                        categoryPicList.push(response.url);
                    }
                });
                this.on("sending", function (file, xhr, formData) {
                    formData.append("filesize", file.size);
                });
                this.on("removedfile", function (file) {
                    var responseJson = null;
                    if (file && file.xhr && file.xhr.responseText) {
                        responseJson = $.parseJSON(file.xhr.responseText);
                    }
                    if (responseJson) {
                        $.each(categoryPicList, function (i, data) {
                            if (categoryPicList[i].indexOf(responseJson.url) > -1) {
                                categoryPicList.splice(i, 1);
                            }
                        });
                    }
                    if (file.name.length > 0) {
                        for (var i = 0; i < categoryPicList.length; i++) {
                            if (categoryPicList[i].indexOf(file.name) > -1) {
                                categoryPicList.splice(i, 1);
                                break
                            }
                        }
                        console.log("文件 " + file.name + " 被移除");
                    }
                });
            }
        });
        bindEventer('authInfo', 30);
        bindEventer('briefing', 600);
        $("#authInfo, #briefing").trigger('keyup');

        getChange();

        //动态添加认证信息
        if ($('#authInfo').val().length > 0) {
            var arr = $('#authInfo').val().split('、');
            $('#authInfo').val(arr[0]);
            for (var i = 1; i < arr.length; i++) {
                $("#info-more").append('<div class="remove-this"><div class="col-sm-10 padding-left-0">' +
                        '<textarea class="form-control" rows="1" name="authInfo" maxLength="30" style="height:35px;margin-bottom: 20px;">' + arr[i] + '</textarea></div>' +
                        '<a href="javascript:void(0);" class="btn btn-sm btn-default col-sm-2" onclick="removeText(this);">删除</a></div>');
            }
        }
        // 教练保存之后进来初始化函数
        init();
    });
	
	function init(){
		var private = $('#private').is(':checked');
		debugger;
		if(!private) {
			$('#private_show').hide();
	        $('#isPrivateBodyExaminationNo, #isPrivateExperienceNo, #isPrivateConsultNo, #isPrivateCoachSortNo').iCheck('check');
		}
		
	}
    $("#gender").change(function () {
        getChange();
    });

    //身材根据性别的改变而动态改变
    function getChange() {
        var option = "";
        if ($("#gender").val() == 1) {
            for (var opt in stature_man_json) {
                option += '<option value=' + stature_man_json[opt] + '>' + stature_man_json[opt] + '</option>';
            }
            $("#bodyStature").empty().append(option);
        } else {
            for (var opt in stature_woman_json) {
                option += '<option value=' + stature_woman_json[opt] + '>' + stature_woman_json[opt] + '</option>';
            }
            $("#bodyStature").empty().append(option);
        }
        var body_stature_option = $('#bodyStature option');
        for (var i = 0; i < body_stature_option.length; i++) {
            if (body_stature == body_stature_option[i].innerText) {
                $("#bodyStature option[value=" + body_stature + "]").attr('selected', true);
            }
        }

    }

</script>

</@body.page>

</html>